<?php

namespace App\Models\Notice;

use App\Models\BaseModel;

class SmsError extends BaseModel
{

    protected $table = 'sms_errors';
    protected $fillable = ['record_id', 'error_code', 'error_message', 'data_scope'];
    public $params = [];

    public function smsRecord()
    {
        return $this->belongsToMany('App\Models\Account\User', 'sms_records', 'id', 'user_id', 'record_id', 'id')->withPivot(['phone', 'user_id', 'content']);
    }

    public function getNoticeErrorList($limit)
    {
        $perPage = $limit > 0 ? $limit : $this->limit;
        $errorList = $this->with('smsRecord:users.id,username')
                ->select(['id', 'record_id', 'error_code', 'error_message', 'created_at'])
                ->paginate($perPage);

        if ($errorList) {
            return $errorList->toArray();
        } else {
            return null;
        }
    }

}
